import {
  ArgumentsHost,
  Catch,
  ExceptionFilter,
  HttpException,
} from '@nestjs/common';

@Catch()
export class HttpExceptionFilter implements ExceptionFilter {
  catch(exception: HttpException, host: ArgumentsHost) {
    const ctx = host.switchToHttp();
    const responce = ctx.getResponse();
    const message = exception.message;
    const status = exception.getStatus();
    responce.status(status).json({
      code: status,
      success: false,
      message,
    });
  }
}
